import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';

/// ../src/materia/constants.dart
/// The height of the toolbar component of the [AppBar].
// const double kToolbarHeight = 56.0;

/// The height of the bottom navigation bar.
// const double kBottomNavigationBarHeight = 56.0;

class Screen {
  static double get _ppi => (Platform.isAndroid || Platform.isIOS) ? 150 : 96;

  static bool isLandscape(BuildContext context) =>
      MediaQuery.of(context).orientation == Orientation.landscape;

  static Size size(BuildContext context) => MediaQuery.of(context).size;

  static double width(BuildContext context) => size(context).width;
  static double height(BuildContext context) => size(context).height;

  /// height of status bar
  static double statusBarHeight(BuildContext context) =>
      MediaQuery.of(context).padding.top;

  /// height of safeArea bottom
  static double safeBottomHeight(BuildContext context) =>
      MediaQuery.of(context).padding.bottom;

  /// 对角线长度 勾股定理
  static double diagonal(BuildContext context) {
    final Size s = size(context);
    return sqrt((s.width * s.width) + (s.height * s.height));
  }

  /// INCHES
  static Size inches(BuildContext context) {
    final Size pxSize = size(context);
    return Size(pxSize.width / _ppi, pxSize.height / _ppi);
  }

  static double widthInches(BuildContext context) => inches(context).width;
  static double heightInches(BuildContext context) => inches(context).height;
}

extension MediaQueryExtension on BuildContext {
  Size get size => Screen.size(this);
  double get width => Screen.size(this).width;
  double get height => Screen.size(this).height;
}
